<style lang="less">
// @import "./supplierManage.less";
</style>
<template>
  <Modal :title="modalTitle" v-model="isShow" :mask-closable='false' :width="400" @on-cancel="cancel">
    <Form ref="percentsetForm" :model="percentsetForm" :label-width="100" :rules="percentsetFormValidate">
         <Form-item label="分销比例:" prop="percent" style="margin-top:20px;">
            <!-- <Input v-model="percentsetForm.percent" clearable style="width: 200px;" :number=true>
              <span slot="append">%</span>
            </Input> -->
            <InputNumber
              :max="100"
              :min="1"
              v-model="percentsetForm.percent"
              :formatter="value => `${value}%`"
              :parser="value => value.replace('%', '')"
              style="width: 200px;"
              />
          </Form-item>
    </Form>
    <div slot="footer">
        <Button type="text" @click="cancel">取消</Button>
        <Button type="primary" :loading="submitLoading" @click="submitReview">提交</Button>
    </div>
  </Modal>
</template>

<script>

export default {
  name: "review-modal",
  props:{
    // isShow: {
    //   type: Boolean,
    //   default: false
    // },
    // reviewObject: {
    //   type: Object,
    //   default: false
    // }
    // reviewModalTitle: {
    //   type: String,
    //   default: ""
    // },
    // reviewStatus: {
    //   type: String,
    //   default: ""
    // },
  },
  data() {
    return {
      isShow: false,
      modalTitle: "",
      percentsetForm: {
        id:"",
        percent: 20,
        type: ""
      },
      submitLoading: false,
      currentDisSetObj: {},
      percentsetFormValidate: {
      }
    };
  },
  methods: {
    openSetModal(isOpen,disSetObj){
      let disSetObject = disSetObj;
      if(disSetObject){
        this.currentDisSetObj = disSetObj;
        this.modalTitle = disSetObject.title;
        this.percentsetForm.id = disSetObject.id;
        this.percentsetForm.type = disSetObject.type;
        this.percentsetForm.percent = disSetObject.billRow;
      }
      this.isShow  = isOpen;
    },

    cancel() {
      this.isShow = false;
      this.$emit('on-close',true);
    },
    submitReview(){
      var _this = this;
      let setObj = this.parseSetObj(this.percentsetForm);
      // console.log(setObj);

      this.submitLoading = true;
      this.putRequest(setObj.url, setObj.params).then(res => {
        this.submitLoading = false;
        if (res.success === true) {
          this.$Message.success("分销比例设置成功");
          this.isShow = false;
          this.$emit('on-set-success',{type: _this.currentDisSetObj.type, flag: true});
        }
      });
    },

    parseSetObj(setObj){
      let type = setObj.type;

      let returnSetObj = {};
      if(type=="LINE"){
        returnSetObj = this.constructSetObj("/line/setup", setObj);
      }else if(type=="HOTEL"){
        returnSetObj = this.constructSetObj("/hotel/setup", setObj);
      }else if(type=="SPECIAL"){
        returnSetObj = this.constructSetObj("/goods/setup", setObj);
      }else if(type=="GOODS"){
        returnSetObj = this.constructSetObj("/goods_item/setup", setObj);
      }else{}

      return returnSetObj;
    },

    constructSetObj(url, setObj){
      let returnSetObj = {};

      returnSetObj.url = url;
      returnSetObj.params ={};
      returnSetObj.params.ids = setObj.id;
      returnSetObj.params.billRow = setObj.percent/100;

      return returnSetObj;
    },

  },
  mounted() {
  }
};
</script>
